使用XMLHttpRequest取得GitHub資料
<html>
<head>
<meta charset="UTF-8">
<title>使用XMLHttpRequest取得GitHub資料</title>
</head>
<body>
<div id="show">
{{ url_data }}
</div>
</body>
<script src="vue.js"></script>
<script>
var demo = new Vue({
el: '#show',
data: {
url_data: []
},
created: function () {
this.getData();
},
methods: {
getData: function () {
var apiURL = 'https://api.github.com/repos/vuejs/vue/commits';
var xhr = new XMLHttpRequest();
var self = this;
xhr.open('GET', apiURL);
console.log(xhr.open('GET', apiURL));
xhr.onload = function () {
self.url_data = xhr.responseText;
}
xhr.send()
}
}
})
</script>
</html>